home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / simula / compiler / cim / amigacim.lha / MathBug.c < prev    next >
C/C++ Source or Header  |  1992-09-13  |  1KB  |  64 lines

  1.  
  2.  
  3. /*
  4.     demonstrate bug of mathieeedoubbas.library 37.1
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. #include <inline/mathieeedoubbas.h>
  10. #include <inline/exec.h>
  11.  
  12. struct Library *MathIeeeDoubBasBase;
  13.  
  14. union convert
  15. {
  16.     double d;
  17.     struct {
  18.         unsigned int s:1;
  19.         unsigned int e:11;
  20.         unsigned int m1:20;
  21.         unsigned int m2;
  22.     } IEEE;
  23. };
  24.  
  25. int main()
  26. {
  27.     double d1, d2;
  28.     union convert conv;
  29.  
  30.     MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library", 0);
  31.     if(MathIeeeDoubBasBase == 0)
  32.     {
  33.         printf("could not open mathieeedoubbas.library\n");
  34.         exit(1);
  35.     }
  36.  
  37.     d1 = -10.0;
  38.     conv.d = d1;
  39.     conv.IEEE.m2++;
  40.     d2 = conv.d;
  41.  
  42.  
  43. #define TEST(a,b,c) printf("%s: %d (should be %d)\n", a, b, c);
  44.  
  45.  
  46.     printf("Show mathieeedoubbas.library 37.1 bug of IEEEDPCmp(d1,d2)\n\n");
  47.     printf("d1 = %.17f, d2 = %.17f\n\n", d1, d2);
  48.  
  49.     TEST("d1 <d2", d1<d2 , 0);
  50.     TEST("d1<=d2", d1<=d2, 0);
  51.     TEST("d1 >d2", d1>d2 , 1);
  52.     TEST("d1>=d2", d1>=d2, 1);
  53.     printf("\n");
  54.     TEST("d2 <d1", d2<d1 , 1);
  55.     TEST("d2<=d1", d2<=d1, 1);
  56.     TEST("d2 >d1", d2>d1 , 0);
  57.     TEST("d2>=d1", d2>=d1, 0);
  58.     printf("\n");
  59.     TEST("IEEEDPCmp(d1,d2)", IEEEDPCmp(d1,d2), 1);
  60.     TEST("IEEEDPCmp(d2,d1)", IEEEDPCmp(d2,d1), -1);
  61.  
  62.     CloseLibrary(MathIeeeDoubBasBase);
  63. }
  64.